home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / sinh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  5.0 KB  |  258 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    sinh   double precision hyperbolic sine
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    sinh
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Returns double precision hyperbolic sine of double precision
  35.  *    floating point number.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    double sinh (x)
  40.  *    double x;
  41.  *
  42.  *  REFERENCES
  43.  *
  44.  *    Fortran IV plus user's guide, Digital Equipment Corp. pp B-5
  45.  *
  46.  *  RESTRICTIONS
  47.  *
  48.  *    Inputs greater than ln(MAXDOUBLE) result in overflow.
  49.  *    Inputs less than ln(MINDOUBLE) result in underflow.
  50.  *
  51.  *    For precision information refer to documentation of the
  52.  *    floating point library routines called.
  53.  *    
  54.  *  PROGRAMMER
  55.  *
  56.  *    Fred Fish
  57.  *
  58.  *  INTERNALS
  59.  *
  60.  *    Computes hyperbolic sine from:
  61.  *
  62.  *        sinh(x) = 0.5 * (exp(x) - 1.0/exp(x))
  63.  *
  64.  */
  65.  
  66. #if !defined (__M68881__) && !defined (sfp004)
  67.  
  68. #include <stdio.h>
  69. #include <math.h>
  70. #include "pml.h"
  71.  
  72. static char funcname[] = "sinh";
  73.  
  74.     struct exception xcpt;
  75.  
  76. double sinh (x)
  77. double x;
  78. {
  79.     if (x > LOGE_MAXDOUBLE) {
  80.     xcpt.type = OVERFLOW;
  81.     xcpt.name = funcname;
  82.     xcpt.arg1 = x;
  83.     if (!matherr (&xcpt)) {
  84.         fprintf (stderr, "%s: OVERFLOW error\n", funcname);
  85.         errno = ERANGE;
  86.         xcpt.retval = HUGE_VAL;
  87.     }
  88.     } else if (x < LOGE_MINDOUBLE) {
  89.     xcpt.type = UNDERFLOW;
  90.     xcpt.name = funcname;
  91.     xcpt.arg1 = x;
  92.     if (!matherr (&xcpt)) {
  93.         fprintf (stderr, "%s: UNDERFLOW error\n", funcname);
  94.         errno = ERANGE;
  95.         xcpt.retval = 0.0;
  96.     }
  97.     } else {
  98.     x = exp (x);
  99.     xcpt.retval = 0.5 * (x - (1.0 / x));
  100.     }
  101.     return (xcpt.retval);
  102. }
  103. #endif
  104. #ifdef    sfp004
  105.  
  106. __asm("
  107.  
  108. comm =     -6
  109. resp =    -16
  110. zahl =      0
  111.  
  112. ");    /* end asm    */
  113.  
  114. #endif    sfp004
  115. #if defined (__M68881__) || defined (sfp004)
  116.  
  117.     __asm(".text; .even");
  118.  
  119. # ifdef    ERROR_CHECK
  120.  
  121.     __asm("
  122.  
  123.  
  124. _Overflow:
  125.     .ascii \"OVERFLOW\\0\"
  126. _Domain:
  127.     .ascii \"DOMAIN\\0\"
  128. _Error_String:
  129.     .ascii \"sinh: %s error\\n\\0\"
  130. .even
  131. | m.ritzert 7.12.1991
  132. | ritzert@dfg.dbp.de
  133. |
  134. |    /* NAN  = {7fffffff,ffffffff}        */
  135. |    /* +Inf = {7ff00000,00000000}        */
  136. |    /* -Inf = {fff00000,00000000}        */
  137. |    /* MAX_D= {7fee42d1,30773b76}        */
  138. |    /* MIN_D= {ffee42d1,30773b76}        */
  139.  
  140. .even
  141. double_max:
  142.     .long    0x7fee42d1
  143.     .long    0x30273b76
  144. double_min:
  145.     .long    0xffee42d1
  146.     .long    0x30273b76
  147. NaN:
  148.     .long    0x7fffffff
  149.     .long    0xffffffff
  150. p_Inf:
  151.     .long    0x7ff00000
  152.     .long    0x00000000
  153. m_Inf:
  154.     .long    0xfff00000
  155.     .long    0x00000000
  156.     ");    /* end asm    */
  157. # endif    ERROR_CHECK
  158.  
  159.     __asm(".even
  160. .globl _sinh
  161. _sinh:
  162.     ");    /* end asm    */
  163.  
  164. #endif    /* __M68881__ || sfp004    */
  165. #ifdef    __M68881__
  166.  
  167.     __asm("
  168.     fsinhd    a7@(4), fp0    | sinh
  169.     fmoved    fp0,a7@-    | push result
  170.     moveml    a7@+,d0-d1    | return_value
  171. ");    /* end asm    */
  172.  
  173. #endif    __M68881__
  174. #ifdef    sfp004
  175.     __asm("
  176.     lea    0xfffa50,a0
  177.     movew    #0x5402,a0@(comm)    | specify function
  178.     cmpiw    #0x8900,a0@(resp)    | check
  179.     movel    a7@(4),a0@        | load arg_hi
  180.     movel    a7@(8),a0@        | load arg_low
  181.     movew    #0x7400,a0@(comm)    | result to d0
  182.     .long    0x0c688900, 0xfff067f8    | wait
  183.     movel    a0@,d0
  184.     movel    a0@,d1
  185.     ");    /* end asm    */
  186.  
  187. #endif    sfp004
  188. #if defined (__M68881__) || defined (sfp004)
  189. # ifdef    ERROR_CHECK
  190.     __asm("
  191.     lea    double_max,a0    |
  192.     swap    d0        | exponent into lower word
  193.     cmpw    a0@(16),d0    | == NaN ?
  194.     beq    error_nan    |
  195.     cmpw    a0@(24),d0    | == + Infinity ?
  196.     beq    error_plus    |
  197.     cmpw    a0@(32),d0    | == - Infinity ?
  198.     beq    error_minus    |
  199.     swap    d0        | result ok,
  200.     rts            | restore d0
  201. ");
  202. #ifndef    __MSHORT__
  203. __asm("
  204. error_minus:
  205.     swap    d0
  206.     moveml    d0-d1,a7@-
  207.     movel    #63,_errno    | errno = ERANGE
  208.     pea    _Overflow    | for printf
  209.     bra    error_exit    |
  210. error_plus:
  211.     swap    d0
  212.     moveml    d0-d1,a7@-
  213.     movel    #63,_errno    | NAN => errno = EDOM
  214.     pea    _Overflow    | for printf
  215.     bra    error_exit    |
  216. error_nan:
  217.     moveml    a0@(24),d0-d1    | result = +inf
  218.     moveml    d0-d1,a7@-
  219.     movel    #62,_errno    | NAN => errno = EDOM
  220.     pea    _Domain        | for printf
  221. ");
  222. #else    __MSHORT__
  223. __asm("
  224. error_minus:
  225.     swap    d0
  226.     moveml    d0-d1,a7@-
  227.     movew    #63,_errno    | errno = ERANGE
  228.     pea    _Overflow    | for printf
  229.     bra    error_exit    |
  230. error_plus:
  231.     swap    d0
  232.     moveml    d0-d1,a7@-
  233.     movew    #63,_errno    | NAN => errno = EDOM
  234.     pea    _Overflow    | for printf
  235.     bra    error_exit    |
  236. error_nan:
  237.     moveml    a0@(24),d0-d1    | result = +inf
  238.     moveml    d0-d1,a7@-
  239.     movew    #62,_errno    | NAN => errno = EDOM
  240.     pea    _Domain        | for printf
  241. ");
  242. #endif    __MSHORT__
  243. __asm("
  244. error_exit:
  245.     pea    _Error_String    |
  246.     pea    __iob+52    |
  247.     jbsr    _fprintf    |
  248.     addl    #12,a7        |
  249.     moveml    a7@+,d0-d1
  250.     rts
  251.     ");
  252. # else    ERROR_CHECK
  253.  
  254. __asm("rts");
  255.  
  256. # endif    ERROR_CHECK
  257. #endif /* __M68881__ || sfp004    */
  258.